import React from 'react';
import Action from '../rd/Action'
import Store from '../rd/Store'
import axios from 'axios'

  
import Reg from '../css/Register.module.css'


export default class Login extends React.Component {
    constructor(props) {

        super(props)
        this.state={
           
            
        }
     
    }
   too(){
    this.props.history.push('/register')
   }
   forg(){
    this.props.history.push('/forget')

   }

    render() {
      
        return (
            <div className={Reg.box}>
               <div className={Reg.logo}>

                    <img src="http://image.fast.126net.cn/group2/M00/01/35/wKgBTFt1O66AHsxxAABSTbPxnPI447.png"/>
                    <h2>会员登录</h2>
                   
                    <p>没有会员账号？<span onClick={this.too.bind(this)}>注册</span></p>
                    
               </div>
               <hr/>
               <div className={Reg.pice}>
                    <div className={Reg.left}>
                       
                    </div>

                    <div className={Reg.right}>
                       <p><span>用户名：</span>
                        <input type="text"  ref="ipt1"/></p>
                        <p>  <span>密码：</span>
                        <input type="text" ref="ipt2"/></p> 
                        <p>  <span>验证码：</span>
                        <input type="text" />
                        <span><img src="https://wanjuyueqi01-mb.126net.cn/RandCheckCode/do?rand=memberLogin "/></span>
                        </p> 
                        <p >
                        <button className={Reg.deng} onClick={this.login.bind(this)}> 登录</button>
                        </p>
                        <p>
                            <span onClick={this.forg.bind(this)}>忘记密码?</span>
                            <span onClick={this.too.bind(this)}>免费注册 ></span>

                        </p>
                    </div>


               </div>
               <div className={Reg.foot}> &nbsp; &nbsp;Copyright ©   &nbsp; &nbsp;2018 琴峰玩具乐器商行. &nbsp; &nbsp; All Rights Reserved 本站内容、图片、视频为网站模板演示数据，如有涉及侵犯版权， &nbsp; &nbsp;请联系我们提供书面反馈，我们核实后会立即删除。</div>
            </div>
        )
    }

 
    login(){
        let _this=this
        axios({
            method:'post',
            url:'http://api.cat-shop.penkuoer.com/api/v1/auth/login',
            data:{userName:this.refs.ipt1.value,password:this.refs.ipt2.value},


        }).then(function(data){
            console.log(data)
            if(data.data.code=="success"){
             Store.dispatch(Action.token(data.data.token))
        // Store.dispatch(Action.res(_this.refs.ipt1.value))
                localStorage.setItem('token',data.data.token)
                 _this.props.history.push('/home')
               

            }else{
                alert(data.data.message)
            }
        })


    }
 

}